package cn.kone.system.controller;

import cn.kone.base.exception.BusinessException;
import cn.kone.base.utlis.R;
import cn.kone.system.dto.LoginDTO;
import cn.kone.system.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILogininfoService iLogininfoService;

    @PostMapping("/account")
    public R<String> account(@RequestBody LoginDTO loginDTO) {
        try {
           String jwtToken =  iLogininfoService.accountLogin(loginDTO);
           return R.ok("登录成功", jwtToken);
        } catch (BusinessException e) {
            return R.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail("网络异常,请稍后重试");
        }

    }

}
